package com.zbs.framework.security.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.zbs.framework.security.utils.PasswordEncoderUtil;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * <p>
 * 
 * </p>
 *
 * @author Zbs
 * @since 2021-02-25
 */
@Getter
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class LoginUser implements Serializable {

    private static final long serialVersionUID = 3497142316462263060L;

    private Long id;
    /**
     * 密码
     */
    @JSONField(serialize = false)
    private String password;

    /**
     * 账号
     */
    private String username;

    /**
     * 入口类型
     */
    private String entryType;

    /**
     * 用户类型
     */
    private Character userType;

    public static LoginUser build(){
        return new LoginUser();
    }

    public LoginUser setId(Long id) {
        this.id = id;
        return this;
    }

    public LoginUser setPassword(String password) {
        this.password = PasswordEncoderUtil.encode(password);
        return this;
    }

    public LoginUser setPassword(String password,boolean flag) {
        if (!flag) {
            this.password = password;
        } else {
            this.setPassword(password);
        }
        return this;
    }

    public LoginUser setUsername(String username) {
        this.username = username;
        return this;
    }

    public LoginUser setEntryType(String entryType) {
        this.entryType = entryType;
        return this;
    }

    public LoginUser setUserType(Character userType) {
        this.userType = userType;
        return this;
    }
}
